package com.glaivelee.firstRefactor;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.glaivelee.abstracts.chooseType;

public class chooseType_backGround extends chooseType {

	int ImagesCount = 1;
	
	public chooseType_backGround(String srcValue,int imagesCount) {
		super(srcValue);
		this.ImagesCount = (imagesCount == 0) ? 1 : imagesCount;
	}
	
	public String exeRex(){
		//正则过滤 
		 String[] patternArr = {"url\\((\".*?\")\\)"};
		 String REPLACE = "";
		 for(int j = 0 ; j < patternArr.length ; j++){
		 	//过滤不需要的字符串  START
		 	for(int i=0 ; i <  clearList.size() ; i++){
				Pattern p = Pattern.compile(clearList.get(i),1);
				Matcher m = p.matcher(srcValue);	 // 获得匹配器对象
				srcValue = m.replaceAll(REPLACE);
			}
			//过滤不需要的字符串 END

			String filterStr = "";
			Pattern pattern = Pattern.compile(patternArr[j]);
			Matcher matcher = pattern.matcher(srcValue);
			int count = 0;
			while (matcher.find()) {
				count++;
				filterStr += "<img " + matcher.group(1) + " />";
				if(count == ImagesCount){
					filterStr += "<br>";
					count = 0;
				}
	        }
      		srcValue = filterStr;
		 }
		return srcValue;
	}

}
